package com.linkage.book.service;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import com.linkage.book.pojo.Book;
import com.linkage.book.repository.BookMapper;
import com.linkage.book.repository.BookRepository;

/**
 * 
 * @author LuoYunHui
 *
 */
@Service
public class BookService {
	
	@Autowired
	private BookRepository bookRepository;
	
	public List<Book> queryAll() {
        return this.bookRepository.queryAll();
    }

    public void save(Book book) {
        //user.setPkId(UUID.randomUUID().toString());
        this.bookRepository.save(book);
    }

    public void update(Book book) {
        this.bookRepository.update(book);
    }

    public void delete(int bookId) {
        this.bookRepository.delete(bookId);
    }

    public Book loadOne(int bookId) {
    	return this.bookRepository.loadOne(bookId);
    }
    
    public Book loadByBookName(@Param("bookName") String bookName){
        return this.bookRepository.loadByBookName(bookName);
    }
    
    public List<Book> getBooksByCategoryId(@Param("categoryId") int categoryId) {
    	return this.bookRepository.getBooksByCategoryId(categoryId);
    }
    
    public List<Book> getBooksByBookName(@Param("bookName") String bookName) {
    	return this.bookRepository.getBooksByBookName(bookName);
    }
    
    public List<Book> getBooksByCombination(@Param("bookName") String bookName, @RequestParam("author") String author,
			@RequestParam("press") String press) {
     	return this.bookRepository.getBooksByCombination(bookName, author, press);
    }
}
